package com.oauth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

import javax.sql.DataSource;

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
//    @Autowired
//    @Qualifier("dataSource")
//    private DataSource dataSource;
//
//    @Autowired
//    @Qualifier("authenticationManager")
//    private AuthenticationManager authenticationManager;
//
//    @Autowired
//    private UserDetailsService userDetailsService;
//
//    JdbcTokenStore tokenStore = new JdbcTokenStore(dataSource);
//
//    @Override
//    public void configure(ClientDetailsServiceConfigurer clients) throws Exception{
//        clients.inMemory().withClient("browser").authorizedGrantTypes("refresh_token","password")
//                .scopes("ui").and().withClient("service-hi").secret("123456")
//                .authorizedGrantTypes("client_credentials","refresh_token","password")
//                .scopes("server");
//    }
//
//    @Override
//    public void configure(AuthorizationServerEndpointsConfigurer endpointsConfigurer) throws Exception{
//       endpointsConfigurer.tokenStore(tokenStore).authenticationManager(authenticationManager)
//               .userDetailsService(userDetailsService);
//    }
//
//    @Override
//    public void configure(AuthorizationServerSecurityConfigurer configurer) throws Exception{
//        configurer.tokenKeyAccess("permitAll")
//                .checkTokenAccess("isAuthenticated()");
//    }

}
